#include "text.h"
#include "ui_text.h"

#include<QProcess>
#include<QDebug>
#include<QStringList>
#include<QString>
#include<windows.h>
#include<QScreen>
#include<QDate>
#include<QGuiApplication>
#include<QPixmap>
#include<QStandardPaths>
#include<QFile>

Text::Text(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Text)
{
    ui->setupUi(this);


}

Text::~Text()
{
    delete ui;
}

void Text::on_pushButton_clicked()
{
    QString desktop_path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);

    QString filePathName = desktop_path;

    filePathName += "/newTextBook-";
    filePathName += QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss-zzz");
    filePathName += ".txt";

    qDebug()<<filePathName;

    QFile createTXT(filePathName);

    if(createTXT.open(QIODevice::ReadWrite|QIODevice::Text)){
        QString temp = "这是一条测试文本"; // 写入内容
        qDebug()<<temp;

        //读取用户输入的内容

        QString str = ui->txtin->toPlainText();
        qDebug()<<str;

        temp=str;
        qDebug()<<temp;

        // 将内容写入文件
        QTextStream out(&createTXT);
        out << temp;

        createTXT.close();
        qDebug()<<"completed.";
    }else{
        qDebug()<<"failed to create a new file!";
    }


    this->close();
}

